package com.zhbr;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;

import com.baidu.mapapi.CoordType;
import com.baidu.mapapi.SDKInitializer;

public class ContextApplication extends Application {

    private static ContextApplication instance;


    @Override
    public void onCreate() {
        instance=this;
        super.onCreate();
        //在使用SDK各组件之前初始化context信息，传入ApplicationContext
        SDKInitializer.initialize(this);
        //自4.3.0起，百度地图SDK所有接口均支持百度坐标和国测局坐标，用此方法设置您使用的坐标类型.
        //包括BD09LL和GCJ02两种坐标，默认是BD09LL坐标。
        SDKInitializer.setCoordType(CoordType.BD09LL);
    }


    public static ContextApplication getInstance(){
        return instance;
    }

    public static Context getContext(){
        return instance;
    }


    public String getToken(){
        return Settings.Global.getString(instance.getContentResolver(),"token");
    }

    public void saveString2SP(String file,String key,String value){
//        Settings.Global.putString(instance.getContentResolver(),key,value);
            SharedPreferences sp = getSharedPreferences(file,MODE_PRIVATE);
            SharedPreferences.Editor editor = sp.edit();
            editor.putString(key,value);
            editor.commit();
    }


    public String readFromSP(String file,String key){
        SharedPreferences sp = getSharedPreferences(file,MODE_PRIVATE);
        return sp.getString(key,"");
    }

    public void removeFromSP(String file,String key){
        SharedPreferences sp = getSharedPreferences(file,MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.remove(key);
        editor.commit();
    }
}
